<template>
  <BasePage>
    <MyTable
      ref="$table"
      :columns="columns"
      :query-schemas="querySchemas"
      :get-data="feedbackApi.list"
      :index="true"
    ></MyTable>
    <MyForm ref="$form" :model-form="model" @submit="handleSubmit"></MyForm>
  </BasePage>
</template>
<script setup lang="jsx">
defineOptions({ name: 'UserFeedback' })
import * as feedbackApi from '@/api/feedback'
import { useCrud } from '@/hooks/useCrud'
const querySchemas = [
  {
    field: 'name',
    component: 'NInput',
    componentProps: {
      placeholder: '算法名称/用户',
    },
  },
  {
    field: 'feedbackType',
    component: 'AsyncSelect',
    componentProps: {
      placeholder: '反馈关联类型',
      options: [],
    },
  },
  {
    field: 'dateRange',
    label: '时间',
    component: 'NDatePicker',
    componentProps: {
      type: 'daterange',
    },
    fieldFormat: 'DateSplit',
  },
]
const columns = [
  {
    title: '反馈关联类型',
    key: 'feedbackType',
  },
  {
    title: '算法名称',
    key: 'algorithmName',
  },
  {
    title: '反馈内容',
    key: 'feedbackConent',
  },
  {
    title: '标签',
    key: 'tag',
  },
  {
    title: '提交用户',
    key: 'submitUser',
  },
  {
    title: '反馈日期',
    key: 'createTime',
  },
  {
    title: '操作',
    key: 'actions',
    width: 180,
    align: 'left',
    fixed: 'right',
    hideInExcel: true,
    render(row) {
      return (
        <n-flex>
          <ActionButton onClick={() => handleView(row)}>操作</ActionButton>
        </n-flex>
      )
    },
  },
]

const { type, model, $form, $table, handleView, handleSubmit } = useCrud({
  name: '反馈',
  customAction: {
    view: '反馈详情',
  },
  initForm: {},
  apis: {
    add: feedbackApi.add,
    edit: feedbackApi.edit,
    del: ({ id }) => feedbackApi.del(id),
    view: ({ id }) => feedbackApi.info(id).then((res) => res.data),
  },
})
</script>
<style lang="scss" scoped></style>
